BASE = block_copy
ELF_TARGET = $(BASE).elf
BIN_TARGET = $(BASE).bin
LD_SCRIPT = $(BASE).lds
ASM_TARGET = $(BASE).asm
READELF_TARGET = $(BASE).r
NM_TARGET = $(BASE).n
SRCS = $(BASE).S
OBJS = ${SRCS:.S=.o}

TC_PREFIX=arm-eabi-
CC=${TC_PREFIX}gcc
LD=${TC_PREFIX}ld
OBJDUMP=${TC_PREFIX}objdump
OBJCOPY=${TC_PREFIX}objcopy
READELF=${TC_PREFIX}readelf
NM=${TC_PREFIX}nm

CFLAGS= -Wall -Wstrict-prototypes -Wno-trigraphs -pipe -march=armv4t -mtune=arm920t
LDFLAGS= -N -X -p -T${LD_SCRIPT}

.PHONY: all clean extra

all:: ${ELF_TARGET} ${BIN_TARGET}

extra: all
	${OBJDUMP} -xS ${ELF_TARGET} > ${ASM_TARGET}
	${READELF} -a ${ELF_TARGET} > ${READELF_TARGET}
	${NM} ${ELF_TARGET} > ${NM_TARGET}

${BIN_TARGET}: ${ELF_TARGET} 
	${OBJCOPY} -O binary ${ELF_TARGET} ${BIN_TARGET}

${ELF_TARGET}: ${OBJS} 
	${LD} ${LDFLAGS} -o $@ $^

${OBJS}: %.o: %.S
	${CC} ${CFLAGS} -o $@ -c $< 

clean:
	-rm -f *~ *.o ${ASM_TARGET} ${READELF_TARGET} ${NM_TARGET} ${BIN_TARGET} ${ELF_TARGET}

